home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr47 / masm.zip / MASM.LBR / GETDIR.AQM / GETDIR.ASM
Assembly Source File  |  1993-04-07  |  3KB  |  68 lines

  1.         TITLE GETDIR - DOS 2.0 Get Current Directory Function
  2. ;       BASCOM Callable subroutine to invoke GETDIR function from DOS
  3. ;              
  4. ;       Written By    John Chapman       CompuServ [70205,1217]
  5. ;       Version 1.0   January 1984
  6. ;INVOCATION:   This procedure is called as follows:
  7. ;           CALL GETDIR(DIRSTR$,drive$,RETCODE%)
  8. ;        DIRSTR$ is a string WHICH MUST BE BUILT BY CONCATENATION !!
  9. ;           (DIRSTR$ = 64blanks$ + CHR$(0) - for example) Creation of the
  10. ;           the string by CONCAT moves the string to string space, and the    
  11. ;           REQUIRED CHR$(0) at the end produces an ASCIIZ string of the 
  12. ;           format required by the DOS service. DIRSTR$ M U S T be 64 bytes
  13. ;           in length, on entry to GETDIR. The field RETCODE% will be set to 
  14. ;           the DOS return code provided by INT 21 FC=3B as described in
  15. ;           the DOS 2.0 manual, or the DOS 2.1 Techical Reference
  16. ;           For stability, the BASIC program must adjust the string length
  17. ;           of the returned directory name: On return, the directory name 
  18. ;           is terminated with a binary zero. Use of the INSTR fuction
  19. ;        will allow creation of a string with correct length.
  20. ;
  21. ; NOTE: The DRIVE$ string must contain a valid drive letter, or "@" 
  22. ;       if the default drive is required. DRIVE$ is not reset on return.
  23. ;
  24. ; It is suggested that the routine calling the service perform some simple    
  25. ; edit and validity checking on the drive letter.
  26. ;
  27. CONST   SEGMENT WORD PUBLIC 'CONST'
  28. CONST   ENDS
  29. DATA    SEGMENT WORD PUBLIC 'DATA'
  30. DATA    ENDS
  31. DGROUP  GROUP  DATA,CONST
  32. CODE    SEGMENT BYTE PUBLIC 'CODE'
  33.         PUBLIC  GETDIR
  34.         ASSUME  CS:CODE,DS:DGROUP
  35. GETDIR  PROC    FAR             ; (NO PARAMETERS)
  36.         PUSH    BP              ; SAVE ENVIRONMENT
  37.         XOR     DX,DX           ; CLEAR OUT dx FOR DRIVE LETTER
  38.         MOV     BP,SP           ; POINT TO PARM LIST IN STACK SPACE
  39.         MOV     SI,[BP]+8       ; POINT TO SECOND PARAMETER
  40.         MOV     BX,2[SI]        ; ACTUAL ADDR OF DRIVE LETTER
  41.         MOV     DL,[BX]         ; LOAD THE DRIVE LETTER
  42.         CMP     DL,90           ; CHECK FOR LOWER CASE,
  43.         JG      LOWER           ; AND GO ADJUST IF LOWER
  44.         SUB     DL,64           ; ADJUST DRIVE LETTER FROM UPPER CASE.
  45.         JMP     DO_STRING       ; GO TO BUILD STRING
  46. LOWER:  SUB     DL,96           ; ADJUST DRIVE LETTER FROM LOWER CASE.
  47. do_string:
  48.         MOV     SI,[BP]+10      ; ==> TO STRING DESCRIPTOR (PARM 1)
  49.         MOV     AX,63           ; LENGTH OF STRING REQUIRED
  50.         CMP     [SI],AX         ; LENGTH : 64
  51.         JNG     BAD_LENGTH      ; EXIT IF STRING TOO SHORT
  52.         MOV     SI,2[SI]        ; ACTUAL ADDR OF STRING VARIABLE 
  53.         MOV     AH,47H          ; SETUP FOR DOS CALL 47
  54.         INT     21H             ; DOS CALL
  55. BAD_LENGTH:
  56.         JC      RC_SAVE         ; PASS RETURN CODE IF THERE (CARRY FLAG SET)
  57.         XOR     AX,AX           ; CLEAR AX (rc=0) IF CARRY FLAG NOT SET
  58. RC_SAVE:
  59.         MOV     SI,[BP]+6       ; POINT TO THIRD  PARAMETER
  60.         MOV     [SI],AX         ; STORE RETURN CODE IN THIRD  PARAMETER
  61. EXIT:   POP     BP              ; RESTORE ENVIRONMENT
  62.         RET     4
  63. TAGIT   DB      "$$$GETDIR$$$"
  64. GETDIR   ENDP
  65. CODE    ENDS
  66.         END
  67.